﻿using Qins.PluginInterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace Qins.Plugins.NotifyIcon
{
    public class NotifyIconViewModel
    {
        /// <summary>
        /// Shows a window, if none is already open.
        /// </summary>
        public ICommand ShowWindowCommand
        {
            get
            {
                return new DelegateCommand
                {
                    CommandAction = () =>
                    {
                        Application.Current.MainWindow.Show();
                        Application.Current.MainWindow.Activate();
                    }
                };
            }
        }

        /// <summary>
        /// Hides the main window. This command is only enabled if a window is open.
        /// </summary>
        public ICommand HideWindowCommand
        {
            get
            {
                return new DelegateCommand
                {
                    CommandAction = () => Application.Current.MainWindow.Hide()
                };
            }
        }


        /// <summary>
        /// Shuts down the application.
        /// </summary>
        public ICommand ExitApplicationCommand
        {
            get
            {
                return new DelegateCommand { CommandAction = () => Application.Current.Shutdown() };
            }
        }


        /// <summary>
        /// 打开插件管理器
        /// </summary>
        public ICommand OpenPluginManagerCommand
        {
            get
            {
                return new DelegateCommand
                {
                    CommandAction = () =>
                    {
                        foreach (var ss in Application.Current.Windows.OfType<Window>())
                        {
                            if (ss.Name == "QinNotifyIcon")
                            {
                                QinNotifyIcon qni = (QinNotifyIcon)ss;
                                MessageContent mc = new MessageContent();
                                mc.messageType = MessageConentTypeEnum.GetAllPlugin;
                                qni.CallPluginRun("Qins.Plugins.NotifyIcon.QinNotifyIcon", mc);
                                break;
                            }
                        }
                    }
                };
            }
        }

        /// <summary>
        /// 打开网址
        /// </summary>
        public ICommand OpenUrlCommand
        {
            get
            {
                return new DelegateCommand
                {
                    CommandAction = () =>
                    {
                        SetUrlWin suw = new SetUrlWin();
                        suw.Show();
                        //foreach (var pwin in Application.Current.Windows.OfType<Window>())
                        //{
                        //    if (pwin.Name == "QinNotifyIcon")
                        //    {
                        //        QinNotifyIcon qni = (QinNotifyIcon)pwin;
                        //        qni.CallPluginRun("Qins.Plugins.NotifyIcon.QinNotifyIcon", "www.baidu.com");
                        //        break;
                        //    }
                        //}
                    }
                };
            }
        }

        public ICommand TopCommand
        {
            get
            {
                return new DelegateCommand
                {
                    CommandAction = () =>
                    {
                        Application.Current.MainWindow.Topmost
                        = !Application.Current.MainWindow.Topmost;
                    }
                };
            }
        }

        public ICommand SettingCommand
        {
            get
            {
                return new DelegateCommand
                {
                    CommandAction = () =>
                    {
                        SettingWin suw = new SettingWin();
                        suw.Show();
                    }
                };
            }
        }
        
    }
}
